<template>
    <div class="front">
        <div class="tab-block-style absolute">
            <div class="tab-block-title">启用系统设置</div>
            <el-radio-group v-model="radio">
                <div class="radio">
                    <el-radio :label="0" :disabled="radio === 1">结束初始化</el-radio>
                </div>
                <div class="radio">
                    <el-radio :label="1" :disabled="radio === 0">反初始化</el-radio>
                </div>
            </el-radio-group>
        </div>
        <div class="tab-btn">
            <el-button type="primary" size="small" @click="save">确定</el-button>
            <el-button type="danger" size="small" @click="close">关闭</el-button>
        </div>
    </div>
</template>
<script scoped>
export default {
    data() {
        return {
            radio: 0           //默认启用
        }
    },
    methods: {
        save() {            //保存
            if(this.radio === 0) {
                this.$confirm('确定结束初始化吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    localStorage.setItem('setRadio', 1);            //保存状态
                    this.radio = 1;
                }).catch(() => {
                    this.$message({message: '已取消操作', type: 'info', duration: 1500});
                });
            } else if(this.radio === 1) {
                this.$confirm('确定反初始化吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    localStorage.setItem('setRadio', 0);            //保存状态
                    this.radio = 0;
                }).catch(() => {
                    this.$message({message: '已取消操作', type: 'info', duration: 1500});
                });
            }
        },
        close(){
            let index = parent.layer.getFrameIndex(window.name);    //先得到当前iframe层的索引
            parent.layer.close(index);
        }
    },
    mounted() {
        let enableStatus = Number(localStorage.getItem('setRadio'));
        enableStatus ? this.radio = enableStatus : localStorage.setItem('setRadio', 0);
    }
}
</script>
<style scoped>
    .tab-block-style, .tab-btn {width: 90%;margin: 0 auto;}
    .tab-block-style {margin-top: 60px;margin-bottom: 20px;padding: 30px 20px 20px;width: 90%;}
    .tab-block-title {font-size: 16px;background-color: #f1f1f1;}
    .radio {padding: 0 10px;box-sizing: border-box;}
    .radio + .radio {margin-top: 12px;}
    .tab-btn {text-align: right;}
</style>